#!/usr/bin/python 
# -*- encoding = utf-8 -*-
from random import randint
import sys
def add_field(file_in,file_out):
    """
        open file_in, add filed ,write into file_out
    """
    f = open(file_out,'w')
    field = "tag_result="
    for line in open(file_in):
        f.write(line)
        if line.find("have_image")!=-1:
            s = ""
            times = randint(0,10)
            numList = randGetNum(times)
            for i in range(len(numList)):
                s += str(numList[i])
                if i == len(numList)-1:
                    pass
                else:
                    s += ','
            newline = field + s +'\1\n'
            f.write(newline)
    f.close()


def randGetNum(N):
    """
        generate N random numbers
    """
    randList = []
    for i in range(N):
        randList.append(randint(1,500))
    randList = list(set(randList))
    return randList


if __name__ == '__main__':
    if len(sys.argv)<3:
        print "usage: " + sys.argv[0] + "src_filename dst_filename"
        sys.exit()
    file_in = sys.argv[1]
    file_out = sys.argv[2]
    
    add_field(file_in,file_out)


